home *** CD-ROM | disk | FTP | other *** search
- * BEGETTER.PRG
- * by Steve Titterud
- * Create any number of data files from a single file, begetter.ext,
- * and do it from within a program without prompting by db3+, even if
- * NO database files are available.
- * Begetter.ext can be created from ANY database file by the following:
- * use <any db3+ datafile>
- * copy to begetter.ext stru exte
- * use begetter.ext
- * zap
- * disp stru then gives the following:
- * Structure for database: C:begetter.ext
- * Number of data records: 0
- * Date of last update : 09/16/86
- * Field Field Name Type Width Dec
- * 1 FIELD_NAME Character 10
- * 2 FIELD_TYPE Character 1
- * 3 FIELD_LEN Numeric 3
- * 4 FIELD_DEC Numeric 3
- * ** Total ** 18
- * This is all we need to create new files from within a program - simply
- * append records which represent the structure of <newfile>, then:
- * CREATE <newfile> FROM begetter.ext
- * How do we get begetter.ext ? We can use dBase III+'s ability to create a
- * catalog file, which is an ordinary .dbf. Opening a catalog file also opens
- * a file called catalog.cat, which documents existing catalog files. Since
- * it's going to be open anyway, let's use IT (catalog.cat) in the first place.
- * Since even catalog.cat may not be available, we create it if absent, or
- * if available, use it as is.
- * Set environment as needs dictate, but the following will do for purposes
- * of demonstrating the idea here. Let's assume you have no .dbf's of any
- * kind available currently:
- clear
- set talk off
- set safety off && no prompts, please
- if .not. file('catalog.cat') && it's not there...
- @ 10,20 say "Creating catalog.cat to generate begetter.ext..."
- set title off && suppress prompt for title
- set catalog to catalog.cat
- set catalog to
- use catalog.cat
- copy to begetter.ext stru exte
- use begetter.ext
- zap && clear out records so we can append records giving desired structure
- erase catalog.cat && it wasn't there in the first place
- else && it IS there...
- @ 10,20 say "Using catalog.cat to generate begetter.ext..."
- use catalog.cat
- copy to begetter.ext stru exte
- use begetter.ext
- zap
- endif
- * Let's use a small and simple file as an example (people.dbf), but any
- * legal file structure (I believe) is possible. Note the lengths of the
- * logical, date, and memo fields need not be supplied. The code here is
- * spelled out step by step, despite its bulk, for clarity. A loop as in
- * Paul C.'s 'creatfil' takes up less space, but its action may not be as
- * obvious to some of the magazine's readers.
- * Let's suppose you want to create a file with the following structure:
- * Structure for database: C:people.dbf
- * Number of data records: 0
- * Date of last update : 09/22/86
- * Field Field Name Type Width Dec
- * 1 NM1 Character 12
- * 2 NM2 Character 15
- * 3 ADDR Character 30
- * 4 CITY Character 35
- * 5 STATE Character 2
- * 6 ZIP Character 5
- * 7 OWES_AMT Numeric 7 2
- * 8 CUST_SINCE Date 8
- * 9 OK_CREDIT Logical 1
- * 10 NOTES Memo 10
- * Total ** 126
- if .not. file('people.dbf') && just in case reader has file by this name
- @ 10,0
- @ 10,20 say "Using begetter.ext to create people.dbf..."
- ** now append records to give desired stucture for later CREATE FROM step
- appe blan
- repl field_name with 'nm1',field_type with 'C',field_len with 12
- appe blan
- repl field_name with 'nm2',field_type with 'C',field_len with 15
- appe blan
- repl field_name with 'addr',field_type with 'C',field_len with 30
- appe blan
- repl field_name with 'city',field_type with 'C',field_len with 35
- appe blan
- repla field_name with 'state',field_type with 'C',field_len with 2
- appe blan
- repl field_name with 'zip',field_type with 'C',field_len with 5
- appe blan
- repl field_name with 'owes_amt',field_type with 'N',field_len with 7,field_dec with 2
- appe blan
- repl field_name with 'cust_since',field_type with 'D'
- appe blan
- repl field_name with 'OK_credit',field_type with 'L'
- appe blan
- repl field_name with 'notes',field_type with 'M'
- use && close begetter.ext
- create people.dbf from begetter.ext && at last, a usable .dbf
- erase begetter.ext
- use
- @ 10,0
- @ 10,20 say "Done !!"
- endif
- return